<template>
	<view class="content">

<view class="abc">
	<view class="deviceStyle">
		<view class="textwidth">
			<text>AGV名称:</text>
		</view>
	{{activeArr.name}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>设备类型:</text>
	</view>
	<!-- {{activeArr.type}} -->
	{{activeArr.type == 2002 ? '单层滚筒AGV':''}}
	{{activeArr.type ==2003 ? '潜入式AGV':''}}
	{{activeArr.type ==2001 ? '双层滚筒AGV':''}}
	{{activeArr.type ==2004 ? '自动叉车AGV':''}}
	{{activeArr.type ==1001 ? '注塑BUFFER机':''}}
	{{activeArr.type ==1002 ? '双层滚筒线':''}}
	{{activeArr.type ==1003 ? '单层滚筒线':''}}
	{{activeArr.type ==1004 ? '立库出口':''}}
	{{activeArr.type ==1006 ? '长滚筒线':''}}
	{{activeArr.type ==1007 ? '提升机':''}}
	{{activeArr.type ==104 ? '充电桩':''}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>是否在线:</text>
		</view>
		{{activeArr.connected == 1 ? '在线': ''}}{{activeArr.connected == 0 ? '离线': ''}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
			<text>当前位置:</text>
		</view>
	{{activeArr.curPosition}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>位置描述:</text></view>{{activeArr.curPositionDescription}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>速度:</text></view>{{activeArr.speed}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>激光区域:</text></view>{{activeArr.avoid}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>循迹:</text></view>{{activeArr.tracing | tracingformatDate}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>电压(%):</text></view>{{activeArr.voltage}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>物料信息:</text></view>{{activeArr.loads | loadsformatDate}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>手自动:</text></view>{{activeArr.manual | manualsformatDate}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>设备状态:</text></view>{{activeArr.isException | isExceptionformatDate}} / {{activeArr.isInvalid ==1 ? '隔离':''}}{{activeArr.isInvalid == 0 ? '正常':''}}
	</view>
	<view class="deviceStyle">
		<view class="textwidth">
	<text>状态描述:</text></view>
	<view class="deviceStyleA">
	{{activeArr.description}}
	</view>
	</view>
	
</view>
<view class="btn">
<button class="buttonStyle warn" @click="quarantine">隔离</button>
<button class="buttonStyle default" @click="mRecover">恢复</button>
</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				activeArr: [],
			}
		},
		methods: {
			// sendPost(){
			// 	uni.request({
			// 		url: 'http://192.168.8.222:8081/makerwit/wms/queryAGVDeviceState',
			// 		data: '{}',
			// 		method: 'POST',
			// 		success:(res)=>{
			// 			console.log('zzzzzzzzzzzzzzzzzz',this.id)
			// 			console.log(res.data.data[0].name)
			// 			//this.activeArr = res.data.data
			// 			for(let i=0;i<res.data.data.length;i++){
			// 				//this.activeArr = res.data.data
			// 				if(res.data.data[i].id == this.id){
			// 					console.log("asjdfjwoijfwiefnvjksdjkgfreifvjsdjf:",res.data.data[i].name)
			// 					this.activeArr=res.data.data[i]
			// 					console.log(this.activeArr)
			// 				}
			// 			}
			// 		}
			// 	})
			// },
			
			async sendPost(){
				const res = await this.$myRequest({
					url: '/makerwit/wms/queryAGVDeviceState',
					data: '{}',
					method: 'POST'
				})

				for(let i=0;i<res.data.data.length;i++){
					//this.activeArr = res.data.data
					if(res.data.data[i].id == this.id){
						//console.log("asjdfjwoijfwiefnvjksdjkgfreifvjsdjf:",res.data.data[i].name)
						this.activeArr=res.data.data[i]
						//console.log(this.activeArr)
					}
				}
			},
			// quarantine(){
			// 	uni.request({
			// 		url: 'http://192.168.8.222:8081/makerwit/wms/updateDcsObjectStatus',
			// 		data: '{\"name\": \"'+this.activeArr.name+'\",\"isInvalid\": 1}',
			// 		method: 'POST',
			// 		success(res){
			// 			console.log(res)
			// 		}
			// 	})
			// },
			async quarantine(){
				 const res = await this.$myRequest({
					url: '/makerwit/wms/updateDcsObjectStatus',
					data: '{\"name\": \"'+this.activeArr.name+'\",\"isInvalid\": 1}',
					method: 'POST'
				})
				console.log(res)
				this.sendPost()
			},
			// mRecover(){
			// 	uni.request({
			// 		url: 'http://192.168.8.222:8081/makerwit/wms/updateDcsObjectStatus',
			// 		data: '{\"name\": \"'+this.activeArr.name+'\",\"isInvalid\": 0}',
			// 		method: 'POST',
			// 		success(res){
			// 			console.log(res)
			// 		}
			// 	})
			// }
			async mRecover(){
				 const res = await this.$myRequest({
					url: '/makerwit/wms/updateDcsObjectStatus',
					data: '{\"name\": \"'+this.activeArr.name+'\",\"isInvalid\": 0}',
					method: 'POST'
				})
				console.log(res)
				this.sendPost()
			},
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
		console.log('000000000000000000000000000000000',option)
				this.id=option.id
		        console.log(option.id); //打印出上个页面传递的参数。
		        console.log(option); //打印出上个页面传递的参数。
				 
				
		    },
			onShow() {
			this.sendPost()	
			},
			filters: {
				tracingformatDate: function (value) {
					if(value == undefined){
						return '';
					}
					if(value == ''){
						return '';
					}
					if(value == 'l'){
						return "左循迹";
					}
					if(value == 'r'){
						return '右循迹'
					}
					if(value == 'm'){
						return '中间循迹'
					}
					if(value == 'e'){
						return '系统停车';
					}
					if(value == 's'){
						return '精准停车';
					}
					if(value == 'L'){
						return '左横移';
					}
					if(value == 'R'){
						return '右横移';
					}
					return value;
				},
				loadsformatDate: function (value) {
					if(value == undefined){
						return '';
					}
					if(value == 0){
						return "无物料";
					}
					if(value == 1){
						return '有物料'
					}
					return value;
				},
				manualsformatDate: function (value) {
					if(value == undefined){
						return '';
					}
					if(value == 0){
						return "自动";
					}
					if(value == 1){
						return '手动'
					}
					return value;
				},
				isExceptionformatDate: function (value) {
					if(value == undefined){
						return '';
					}
					if(value == 0){
						return "正常";
					}
					if(value == 1){
						return '异常'
					}
					return value;
				},
			}
	}
</script>

<style lang="scss">
	.content{
		width: 100%;
	}
	.deviceStyle{
		display: flex;
		line-height: 80rpx;
		.textwidth{
			width: 180rpx;
		}
	}
.abc{
	padding: 5px;
	}

	.default{
					background-color: $uni-color-primary;
					color: #FFFFFF;
	}
				.warn{
					
					background-color: $uni-color-warning;
					color: #FFFFFF;
				}


.buttonStyle{
	width: 30%;
	display: flex;
	justify-content: center;
	align-items: center;

}
.btn{
	display: flex;
}
.deviceStyleA{
			width: 570rpx;
			word-wrap: break-word;
			word-break: break-all;
			white-space: pre-line;
		
	}
</style>
